import {
	mapMutations
} from 'vuex'

export default {
	...mapMutations([
		'upUserInfo',
	]),
	//展开收起
	isOpen() {
		this.isMore = !this.isMore
	},
	share() {
		// this.$refs.popup.open()
	},
	//打开评论弹窗
	//打开评论弹窗
	openComment(level_or_id, place) {
		if (level_or_id == 'level1') { //true为评论二级
			this.parentId = null
		} else {
			this.parentId = level_or_id
		}
		this.place = place
		this.$refs.send.open()


	},
	sendPopChange(e) {
		if (e.show) {
			setTimeout(() => {
				this.isFocus = true
			}, 100);
		} else {
			setTimeout(() => {
				this.isFocus = false
			}, 100);
		}
	},
	selectShop(item) {
		this.shopCurrent = item
	},
	//键盘回车
	sumbit_comment() {
		this.addInformationComment(1)
	},





	//键盘回车
	sumbit_comment() {
		this.addInformationComment(1)
	},
	//页面数据
	getData() {
		let that = this
		this.detail = JSON.parse(uni.getStorageSync('preview'));
		if (this.detail.filesList.length <= 1) { //轮播图的点点
			this.dots = false
		}
		//高度自适应
		if (this.detail.filesList[0].fileSuffix == 'png' || this.detail.filesList[0]
			.fileSuffix == 'jpg' || this.detail.filesList[0].fileSuffix == 'jpge') {
			const getSystemInfo = uni.getSystemInfoSync()
			const {
				windowWidth
			} = getSystemInfo; //屏幕可视宽高
			console.log("屏幕宽度", windowWidth)
			this.$nextTick(() => {
				setTimeout(() => {
					const query = uni.createSelectorQuery();
					query.select('.cover_img').boundingClientRect(data => {
						that.swiperHeight = data.height;
						console.log(data, "图片高度");
					}).exec();

				}, 100)

			})

		} else {
			this.swiperHeight = 550 //图片之外的高度
		}
		// 自动播放视频
		this.detail.filesList.forEach((item, index) => {
			if (item.fileSuffix !== 'png' && item.fileSuffix !== 'jpg' && item
				.fileSuffix !== 'jpge' && index == 0) {
				this.currentVideo = 'video' + index
				//获取 video 上下文 videoContext 对象
				this.videoContext = uni.createVideoContext(this.currentVideo);
				uni.createVideoContext(this.currentVideo, this).play();
			}
		})
	},
	toggle(index) {
		this.control = true
	},
	//切换暂停视频
	changeVideo(val) {
		// console.log(val.detail.current)
		let _this = this;
		let currentId = 'video' + val.detail.current; // 获取当前视频id
		console.log(currentId, '切换视频')
		//播放选中视频
		uni.createVideoContext(currentId, _this).play();
		// 获取视频列表
		let trailer = _this.detail.filesList;
		trailer.forEach((item, index) => { // 获取json对象并遍历, 停止非当前视频
			if (item.fileSuffix !== 'png' && item.fileSuffix !== 'jpg' && item.fileSuffix !== 'jpge') {
				let temp = 'video' + index;
				console.log(temp, currentId)
				if (temp != currentId) {
					// 暂停其余视频
					uni.createVideoContext(temp, _this).pause(); //暂停视频播放事件
				}
			}

		})
	},
	fullscreenchange(el) {
		// el.detail.fullScreen
		let _this = this
		if (el.detail.fullScreen) {
			_this.objectFit = 'contain'
		} else {
			_this.objectFit = 'cover'
		}
	},
	openVideo(index) {
		this.currentVideo = 'video' + index
		//获取 video 上下文 videoContext 对象
		this.videoContext = uni.createVideoContext(this.currentVideo);
		// uni.createVideoContext(this.currentVideo,this).play(); 

	},
	//加载图片完成
	imgloadComplete(e) {
		let that = this
		const getSystemInfo = uni.getSystemInfoSync()
		const {
			windowWidth
		} = getSystemInfo; //屏幕可视宽高
		console.log("屏幕宽度", windowWidth)
		const query = uni.createSelectorQuery();
		query.select('.cover_img').boundingClientRect(data => {
			that.swiperHeight = data.height;
			console.log(data, "图片高度");
		}).exec();
	},
	// 预览图片
	previewImage(url, index) {
		uni.previewImage({
			current: index, // 当前显示图片的链接/索引值
			urls: [url], // 需要预览的图片链接列表，photoList要求必须是数组
			loop: true // 是否可循环预览
		});
	},
	//展开评论
	moreComment(index) {
		this.list[index].isShow = !this.list[index].isShow
	},
	getUserInfo() {
		let that = this
		that.$httpRequest.request({
			that: that,
			url: 'wechat/info',
			method: 'get',
			params: {

			},
			success: res => {
				if (res.code === that.$httpConfig.SUCCESS_CODE) {
					that.upUserInfo(res.data)
					console.log(that.userInfo)
					// setTimeout(function () {
					// 		    uni.hideLoading();
					// 		}, 200);
				} else {
					that.upUserInfo({})
				}
			}
		})
	},



}